#include "simpledbus.h"
#include "dbusservice.h"

#include <QDBusConnection>
#include <QtDBus>
#include <QDBusInterface>
#include <QMetaObject>
#include <QDBusAbstractInterface>

SimpleDbus::SimpleDbus(QDeclarativeEngine * e) :
    QObject(e)
{
     this->engine = e;

     qDebug()<<"init serveur signaux DBUS";
}

/*void SimpleDbus::registerDbusService(DbusService dbs){
    engine->rootContext()->setContextProperty(dbs.signalHandler(), dbs.dbus());
}*/

void SimpleDbus::registerDbus(QString name, QString service,QString path){
    qDebug()<< "dbus connect name "<< name;
    qDebug()<< "dbus connect service"<< service;
    qDebug()<< "dbus connect path"<< path;

    QDBusInterface* serv = new QDBusInterface(service,path,QString(), QDBusConnection::sessionBus(),this);
    qDebug()<< "IS valid" << serv->isValid();
    engine->rootContext()->setContextProperty(name, serv);
    qDebug()<< "dbus OK" ;
}

QVariant* SimpleDbus::v(QString name){
    QVariant v = engine->rootContext()->contextProperty(name);
    return &v;
}

/*void SimpleDbus::invokeDbusMethod(QString methodName,QList<QVariant> argumentList){
    QDBusPendingReply<> replay = this->asyncCallWithArgumentList(methodName, argumentList);
    replay.waitForFinished();
    if(replay.isError()){
        qDebug()<<"error while call:"<<replay.error();
    }
    //return replay.value();
}*/
